Cherry pick PR #299 and #305 on ORM