cleanup and documentation for replaceLast