several bugfixes and passing tests (most)