Got rid of main
Some refactoring and cleanup