Fixed some bugs so that the program can run.