fix bug causing sql syntax error