began refactoring to be clearer to read