i added comments to the code to explain what was going on, maybe it is just easier to create two seperate sections in the chapter covering each approach
working and tested