more tests and fixed impl