Fixed wrong index computation