refactor tooltip generation