Add test and refactor entity special cases