Rewrite the module

Much simpler code now. Also fixed some bugs and unused code. Rewrite the tests to be simpler. And fixed code style and other things.
Merge pull request #11 from sindresorhus/rewrite

Rewrite the module