major refactor begun using optparse