Fixed various bugs found by new specs.