Cleanup the sample taking code so it is more readable.