Added loop block.
Modified
Divided main routine to sub routines.