refactoring code, stuck with nonfunction DB