Fixed Bad Access

So,

i must fixed a bad access bug and also optimized the code.