lots of fixes for mass refactor