finished Cij code