refactor test and update code