working lab4 code