extracting main to a separate class and some minotr refactorings