main and other refactor