minor corrections to pablo's code with saving