added some useful comments for understandability