Ugly, but it works