remake of sql parts [in progress]