updated fig 5 code