Refactor to use postgre