Yes, the second version indeed works. Committed the new version with even less lines of code. :)