I agree that your approach is better than my code.
I will fix it and re-commit soon.