Fix for bug 1020440, 1021041, 1021462, 1021467, and a typo