Clean up the the implementation, improve the naming, and add some more documentation as well as more in-depth tests.