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.
`files` wasn't used anywhere, so I removed this. No idea what it was supposed to do.