Fix for #51 and #112