Move save to separate function