Adjusted to handle small images