Added more tests and refinements.