refactor of main