Fixed fatal bug that caused program to run infinite loop.

Also fixed the switch case.