Fix errors occuring when optimization level greater than 0

Among other things.