refactoring, digging into pg performance.