Added check for empty activities matrix