Bugfixing invalid array access