Fixing CARBON-14782, and adding some tests.

Signed-off-by: Jayanga Dissanayake <jsdjayanga@yahoo.com>