Quick union code. Can be improved