made test code a separate function