code and explaination