Applied patch from bug #2737
Applied patch from bug #2756
Added patch from bug #2752
Make declarations in header match implemenations

Fixes #2789
Return nil where pointers are expected

Fixes #2790