Fix for NoneType errors