Fix a NPE in certain callback cases. Add a couple of useful and predefined functions.