added code and comments