used anonymous function to work around sql callback limitation