final solution for saving images (must be tested)