cleaned and commented code