some refactoring to remove redundancies