Refactor Spreadsheet code