Fix for bug 1021041, 1021462, 1021467