Also changes some function params, but this is ok. Some simplifications were also able to be made (ie. killing off strcmps with ==, etc).
and some things suggested by cppcheck and compiler warnings.