Restore copyArrayPos, remove copyArrayLen and make sure to declare variables in right scope