looks like there are some duplicated code here. Could we put then under util and use them for tests?