refactor entity code