Made all functions which request database connections release them after they're no longer necessary.