Fix problems with empty (NULL) sessions, formatting