refactored code
updated version