Modularized code a bit more to increase maintainability