Refactoring code and making it more OO