refactoring and change some db staff