minor changes to several files
reorganizing code