moved tests into a function