fixed wrong indexes and added more comments