Fix for incorrect row removal with function

When more than one row was removed, sometimes the wrong row would be
removed due to the direction of removal (first to last rather than last
to first).