Memory leaks

Some very big memory leaks have been fixed in this commit. The biggest one was
where if you loaded a language (these can get very big) it never got freed.