added more comments and deleted unused code