Fixed bugs that were causing the program to crash while running.