def trim_block(block):
    """Removes comments from the beginning and empty lines from the end."""
    if block and block[0].startswith('#'):
        block.pop(0)
    while block and not block[-1].strip():
        block.pop(-1)
