Moved argument handling out of the main function