Changed anonymouse functions to named functions.