Some -O3 fixes thanks to Agrabren