Cleaned and commented up the code