cleaned up UnionWithRect function