simplify thumbnail code
bug fixes