Attempted fix of null ref errors