this is working "refactored" code