moved test stuff into separate function