Cleanup, split the library into two files and added some comments.