Modified logic. Updated comment. Added validation.