complete rank filter implementation