Refactor main.js before file type detection