debugged calculation for out of base boundry