removed unnecessary line setting prev = head.