more tests and simplify code