Fix poor syntax and edge case bugs.