modified initial code