Core bug fixes

Fixes for #147 and #148