fixed bug on boundary
boundary detection