Refractored code and added boilerplate