Fixes for the previous commit (r21266), as the code was not being used and was buggy.
Authored by: bugman 2013-10-27
Parent: [r21266]
Child: [r21268]