although this "if" block has different actions from the later one (this for pak, next for res), but I prefer to merge the two "if options.mode == 'embedded':" into one, and add a comment to note it