Adding some C to the bash version
Removing the memory leaks