nil pointer bug fixed