Explain the code step by step