Corrected an issue with boundary detection