Merged Venkat's code with Sibi's and Eric's.