What is the $N? Do you mean to have $1 in all of those? And if so, your while loop already checks if $1 != $null, so your IF statements inside the loop that check that aren't needed.
Also, it is usually a better idea to leave a menu "clean" rather than having a lot of code in there. Have your menu item call and alias instead of having everything in there and it will make the menu a lot more readable.