Adding a length check to the first function