The only way to reliably fix this is to institute some form of judgment of whether or not an actor was following the spirit of the law. If they weren't they should have any advantages gained by skirting the law removed by force.
Of course this leads to a different set of problems with the potential for overreaching state actors. One way to combat this could be making the judicial branch much more independent than it usually is in most countries.