Tidied up save function