begin splitting program into several simple functions