pg refactor