added more error handling to avoid crashing on empty <p> tags