Fixed bug in main function