minor code refactoring and test plan fixes.