Fixed some globals issue and switched tests to use a test db