Add result writing functionality