Merge Daniel's fix with Madhu's recent work.