fix some tests
refactor the code