Fix bugs in entity generation