improved thumbnail code