Fixed tests and code