Refactoring to make stuff a bit cleaner