So here's my current version of the plugin:
https://gist.github.com/splewis/8967187
I don't think it'll be very useful to see my changes, pretty much all I did was remove things.
I've still got an issue of some people getting placed on teams after 8 are already on the server - but I think it's because of my changes to setting up the teams (see my g_numT and g_numCT variables).