Refactor saveGoal into separate file