Made code a bit more modular