move logic from test file to library file