refactor tooltip code