refactored initial check to explicitly return nil and avoid initializing variables