Not 100% happy with this soultion, but it works and I don't see any better ways to do it.