Multiple fixes to help porting.

Fixed a few minor issues that cause problems porting existing applications to using nan.