First working version, which also prints results to the screen