Works in linux no memory leaks, needs commenting