Added border detection