Refactoring to make code nicer