added conditional z shift routine