Now works perfectly in ie9 and above, and close to perfect in ie8

Add a limit in here to avoid recursing indefinitely. Maybe 50?