Added a nil check before inserting in a dictionary. Was causing crashes.