Type checking always makes me cringe, but I can't think of a better way offhand.