Removed 1 state and made (dis)connecting more robust
Added first functions for optimization