aravin's fixed code