Refactoring to save new pictures in database
index not working properly