rearanged and commented everything