Fix image loading into byte array and loops