added rogosa's solution code