fixing nilClass error