A less naive approach to the problem.  The last commit caused an app I'm working on to panic