major code refactoring continued