Added all tests, and code changes