Fix spelling.
Add FoldingFailedException.
Fix some flake8 complaints.
Remove unneeded isinstance check.