reworked sql stuff