Added many tests and fixes.