cleaned up main function a little