refactoring code and clean db