Refactored code, add comment