fixes for key not found and null reference exceptions