General fixes, improvements and refactoring.

Lambda work.