More informative errors for preview pane and some refactoring

Fixes #17.