rewrote part of main()