Fixed possible segmentation fault