Refactor main file to use optparse