boundry checking added