A bit of a clean up and a refactor - you may want to update to merge this before doing anymore work