Updated to work with postgres