began refactoring of the code