implement all necessary functions, fix mem leaks

Valgrind still reports "Conditional jump or move depends on
uninitialised value(s)". But I think this is based on the fact
that the array of node pointers isn't initialised to something in the
create_map function.