Max msg

This patch set adds an upper limit to the msg parameter passed in the library functions. Moreover it allows for that parameter to be NULL (when ignored).