Fixed hash writing in DB