bug fix. avoid NoneType exceptions