Vikram's patch. Couldn't apply via am so edited manually.