Refactoring of code to be more encapsulated