Fix issue with corrupted greyscale images.
Fix invalid window reference.