Fixed up the sql statements