added comments for understanding code