updated version of the cube code