fixed the index bug introducted with the new scoping