Minor modifications: some cleaning and basic output to file.