Mostly bug fixes, doesn't work at the moment

tests work though