finalized z code