Fixed program crashing when it is optimized