Fixed a few bugs and finished the TODOs for case handling