Fix tests and code