Sorted out the logic for thumbnail generation, removed old code