Minor refactoring

Removed some code duplication