Refactoring some of the code to make the class inheritable