more tests and refactory