Not pretty but it works for some reason.