Add check to avoid reading past array bounds in CommandClass