some SQL corrections