@Osmose took your advice anyway. This is more robust and correct. Feels better. Take one more look at it if you wouldn't mind.