Code explanation

Here.