Made code slightly more modular