updated things
refactored to be a bit easier to navigate.  split things into functions