Added image writing on disk incase of NullPointerException