refactor and handle StopIteration exception

reduce preview quality to 1 incase people prefer to use a javascript
based previewer or something fancier