add boundary detection