Move save functionality into another file.

Also, clean things up and make function names more
meaningful.