Attempt to make the code more modular