This can be done ten times faster and easier with a single option in the menu and with a fair amount of code.