Cleaned up postgres/query a little bit.