codegenerator and some bugfixes