Some cleanup and added more comments.