Sql bug fix and to do list