Refactor main into file and compile steps