major unfinished refactoring