fix nil pointer bugs