fix sql inconsistencies