ugly, but it works