Cleaned and commented the code.