First Big Refactor to make the code more modular