completed the support to lambda and refactored with some exception and error handling