Adding test case and bug fixes.