cleaned and commented the code