Added some comments for clarity. Fixed a missing semicolon.