creating main - minor refactoring and cleanup