Session may expire during long scan

Implemented re-login procedure. Also got rid of warnings.

A race condition is still possible at some points.