Refactor test and add docs