Fixing CARBON-14782, and addding testcases.

Signed-off-by: Jayanga Dissanayake <jsdjayanga@yahoo.com>
Merge pull request #38 from jsdjayanga/master

Fixing CARBON-14782, and addding testcases.