(broken do not merge) wip bug fixes and refactoring