Fix for #45 and #52