minor refactoring.
Big old bug fix