fixed connections
* some improvements suggested by @Gacko