Fixed a switch statement bug and added more debugging code