Refactoring code to OOP