Fixed some bugs in select and insert