Fixed the length function