I don't really like this, but I couldn't quickly think of a better way. Suggestions welcome.