some refactoring to reduce code