Changed to save only non-zero lines to history