refactor p_database