bug fix for array offset calculation