more refactoring for correctness sake