Improve validation macro so it doesn't require caching instances

Hi, we have been using a modified version that doesn't requires caching for a while, so I figured I'd submit it here.