KeyError bug fix in views