Improtve boundary finding