Changed if len(history): to if history: