add checkOutOfBound function