Fix boundaries check on internal array
Eliminate NPE

relates to #231