refactored and added comments
refactored and added comments