Fixed some bugs in the generation of the bases and some other cleanup things.