Bugfix: order of arguments in function call.
Bugfix: check for null ptr before use.