Updated Code with Comments