Added copious comments, cleaned up the code.