praveen|make pay function more robust