added more comments, and documentation