Fix errors in main function