at a quick glance, seems to work as expected, and probably solving the issues discussed in this thread