bug fixes + better postgres compatibility