cleaned up the script and moved things into some functions I can easily pass things to in a map()., should work would with any combination thrown at it.