Some bugfixes after rudimentary testing