Made the world a better place.

Fixed bugs, refactored, added docs, added tests.