bug fixed for nil pointer