refactor bitmapData loop