fixes for key not found and null reference exceptions

Me too :-) I've just extended the unit tests for those so I'll push that up now for you