made code a bit neater even though everything is in main()