Fixed tests and algorithm