Major portability changes to make porting easier