simplified sample refactored to put the non-io code in one easy to use function