refactored helper code so that more functionality is automated.