fix todo, write and fix some tests and other changes