Handling segmentation fault, code optimizing...