main scope re-organized and commented