Cleaning the code a bit, and improving documentation