MDL-35731: Rebased code, done minor comment and code changes