Fixed the extra space bug in the main function