refactor index function with multimethods