added comments for logic