First complete version. Initial tests.