major refactor

... this is going to be a problem to merge...