refactored, now capable of saving images into database