Nice one. Thanks for sharing it for the next person.
BTW you need to format your code a special way to make it easy for others to read. The trick is here.