refactor internal codes to use lamda expressions.