improved bmp drawing and added some error checking