added refactored version