refactoring program main to make it more extensionable