Minor improvments
Improve connection management to be less error prone