bugfixes

some bugfixes on missed mallocs for the insert function.
code cleanup for sanity