added code explanation