Fix bug which causes timeperiods not to be updated.
Improve error messages for socket error.