Moved some code of main method