Rewrite - Now actually works (sorta)

Rewrite of the code. Now works (when running "node test.js") but
additional testing needed to ensure it actually does work.