refactor parse part of main into a separate file