added comments and removed intermediate variables