created main function and fixed various issues