Below are some basic tips that I always recommend to use during the development of plugins to increase the stability and robustness of the code:
1 – Use context.depth property
Useful to check all those situations in which the code in a plugin causes the activation of the same plugin generating a loop!

2 – Use GetAttributeValue instead of Entity.Contains for attributes
Useful to manage the given key was not present in the dictionary error! This approach returns a Null value or Default Value if attribute is not present into attribute collections and you will manage a logic correctly.

3 – Do the Entity Check
Useful to check if the plugin is fired from your target entity.

Add in the comments below your tips to not be forgotten!
Hope it helps and happy 365Power’ing!