Some optimisations in Thread and image handling