reworked for postgre