changed from exiting to returning values. to make testing easier.