Fix some warnings and add optimize flags