Simplify sql and move callback handling to utils