Restructured code so functionality is separated out into separate modules.