C implmenetation now working. Zero memory leaks.