more refactoring and OOPification