Documentation, changes the malloc prototype, logging

Nothing really changed in this request, just more tidying up and documentation and me reading through the code to make sure I have a handle on it. Still none the wiser about the invalid opcode thing :/

Also changed the malloc prototype to malloc(size_t) to match what's said in the man pages for malloc.