optimized image loader code