Refactored checking array bounds