Removed unused code and added some more detail to comments.