`elements` is now a generic function instead of a big switch statement.