Fix undefined method `length' for nil:NilClass"

Just return `nil` for nil input