reworked sql engine