Improve logic for loading resources