rearanged for better reading, also commented