refactorings to reduce code