added boudary check