Bug fix. avoid NoneType error