refactored only using pgsql now.
fmp.js