new refactored version