changed the code to calculate lamda.