Applied Viona's bug fix patch. (Thanks to Viona)