<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def extension(filename):
    '''Properly extract the extension from filename'''
    filename = os.path.basename(filename)
    extension = None

    while '.' in filename:
        filename, ext = os.path.splitext(filename)
        if ext.startswith('.'):
            ext = ext[1:]
        extension = ext if not extension else ext + '.' + extension

    return extension