added support for NSData. Fixed warning about using freed memory