modified Karans program to work