Almost complete, just some memory leaks I think (Valgrind reports no errors! :D)