Refactored duplicated loop logic inside load_sprite_pak(...)