more refactoring and db migration