refactored code, made it more object friendly