initial code and explanation