Added error estimate and fixed some memory issues in the library