Refactor code to check for terminal sharing