filterByPerimeter modified