Small cleanups and fixes.
Rolled back changes to the switch case statements. Added necessary checks to the parent calling function.