Simplify image stack code