Refactored & added comments