did some work to improve existing code
I really need to remember to add before commit