Fix some database issues which came from old bugs