I've changed this logic a bit (see the tests). The eval() stayed, but it shouldn't be a problem (see comment).