cleaned saving code