Here is a better version which actually seems to work correctly and is compat...