Added callback to prevent SQL errors. Fixed bug in sorting.