fixed bug and update sql