major code refactoring