main function bug