fixed return from main error, did some refactoring