changed approach, refactored code  accordingly