some refactoring to make code more legible