bugfixes of while code generation