major refactor of main