Adopted new code from Rupam