fixed some SQL erroring issues