Add check for None and fix possible warning.