adjusted code and comments