See this gist I've just made for some suggestions.
Is it possible to have a rough test-case just to evaluate the correctness of both versions?