Changed few anonymous functions to function references
To avoid Callback Hell, changed a few anonymous functions to function references