refactored nil checks to if-let