Some portability improvements (not really portable yet).