simplify function selection code