lots of refactoring
compileable again