Refactored main and put it in a simple place