Fix two bugs reported by Ashwini Sharma.
Fix another bug reported by Ashwini Sharma.