clean up and clarify overlong function into two clauses