Fixed code, working index