refactored code in try2