Changed some memory management, now purely ANSI C