tad more unit testing and refactoring