Move functioning DB code from test to index