Added comments about purpose of encapsulating code in anonymous function