Removed lambdas, and simplified some code