make function filterLastNValues() workable