added safety checks for locations and segments.