delete old function

delete old function about database and add new one that work correctly