Improve logic, add comments [RD-20]