Fixed up some SQL