Cleaned and commented code