Refactor some functions for readability
More encapsulation