Bug fix for length script