started deep refactoring of code