refactor code to allow changing tab connections

this is work in progress. Please look at the code and give feedback
see #2 for more details