Changed nil checks to use isNil helper function instead