Added code to compute Z value using both alpha and beta matrices