Fixed a slew of minor bugs and syntax errors triggered by edge cases