refactoring and making more object oriented