major refactoring of code