Replace anonymous function and closure with prototype function