Misc portability patches