Wow, thank you so much! I would have never been able to figure this one out!
One thing though, these 2 functions are inside a plugin, is it somehow possible to make this work inside a plugin, or does every user of the plugin has to add this line to their Target.cs file?