initial modifications to decouple postgresql and add write permission checks