corrected behaviour when z=0 or z=spacesize