Just some refactoring to reduce duplicated code