refactored core and test code