refactoring of all code