Cleaned and added more comments to the code.