Fixed solution with answer from http://fpish.net/topic/Some/0/76197