#123 Added checks to avoid crashing on TypeErrors