Refactored original implementation