fixed sql syntal and some bugs