refactor save method into several cohesive functions