rewrite with an eval/apply approach