done some more work on main, sorting files etc