added mutator function with nested while loop