Moved handle_filename code in a function.