added a check for the length