Fixed a bug that occurred from switching databases

There was a reference being held to a previous database when switching.