Refactoring to save pictures in database