z<3 instead of z<=3 for writeCube function