DRY refactoring and cleanup