Fixed SQL errors