refactor test and provide function