ugly, but works