nugfixes and mods to the main routine