changed conditions for writing to db