refactoring
moved functions to bottom of file
GNUified command line interface