fixed: open statement inserted in wrong place
extract entity refining logic into Entity.tryCreate