refactor appdatabase