Fix for Issue234

Also contains a few other small bugfixes