Added comments.
Updated code for readability.