Fixes for -O3 optimization