Fix for #51 and #411