Not pretty, but it works