Merge with Mikael's version to correct the gcc 4.6 compilation issue.