Adding code written by Anil Kag