added conditional to check if dictionary key exists, fixes #482
merging t482 with master