Rewrite everything.

It's more modular and easier to test and maintain. It may be not
perfect but it will make the next features faster to write.