minor syntax and SQL statement fixes