fixed for loop and updated cardname function