better length checking