[#10] refactored the saving code slightly