Added main method for console

Refactoring too