Fix various minor issues in the compiler

The commits explain what each fix does.