fixed use of newentity prior check for nil