refactor to more better fix and add some more tests