Changes on top of Prashant's patch.

Closes #316