Fix for #1038 and #1039