adding function to check bounds