refactor tests and codes