Added comments, improved readability.