Refactor delegates and improve formatting

Change: usage of delegate keyword to lambda delegates.
Change: improve code formatting with more whitespace.