Further refinements and refactoring for pgplsql functions.