Replace all while loop with for.
More fixes for Bitmap Format (other formats' fixes coming soon)