Database extension + refactor