Resolved bug where length was not calculated before it was used as a check.