Main programs and tidy-up.