Fixed check_line function