Fix imageStack function