Moving the lock around.

Signed-off-by: Martin Raspaud <martin.raspaud@smhi.se>