fixed memory lekeage and added docs