refactor some code in a trySaveAll method as it will be useful elsewhere