Refactor code
raw version of save. Needs a tidy up