Fixing some #389 bugs. Still need to test some more.