Refactor flyout code so flyouts can be used in other places