fixed bug 'undefined method length for nil:NilClass'