Portability fixes from Jim Phillips