:) I see this is what you had... I'd just turn this into a generic utility function at the top which is easier to read.  Also, add a docstring.