added some documentation, minor tweaks to the code