Tidied up source files by combining files. Also used assertions after mallocs for safety. And removed unneeded structures for less memory usage