Improved, cleaner fix for #230. Also fixes for #234