added a little thumbnailing magic
some effort to stop flicker when closing viewer