refactored code into a more gem like format