added more comments, removed unused code