Re-wrote solution + added codex

The old solution was not simple enough
Merge pull request #706 from abhinavc/master

Rewrote solution + added codex