Fix compiler warnings in release mode, and clean up build script