Move the code to do the finding out of main() and into it's own function