small refactoring for fix logic error 'array access results in a null pointer dereference'