added comments explaining the optimiazations