Various bug fixes, code gen works