Make my ugly hack *slightly* less ugly

Or at least more robust. For a hack.