Fix major bugs that broke the program