This is a bit ugly, but I'm not sure what the better refactor is.