Removed unused imports.
Rewrote main length finding function.