refactored, minor code and test fixes
refactored, minor code and test fixes