Add some tests along with appropriate fixes.