move hisotry function to individual file
remove hisotry function & free sql malloc