fix tests; bug fixes