Refactor the interactive part into a separate sub