Refactor of main module. Added type signatures. Removed unused imports.