Ugly, but working as intended, I think!