added codes and comments