add refactored version of test code