Seg fault in prefix_search corrected. More tests added.

There was a segmentation fault when prefix_search returned large result sets. I changed the way message environment was alloced a released by result basis. Previously the message environment was created at the beginning of the operation and released at the end causing the afford mentioned segmentation fault.