wrote crux of main function