Refactored data manipulation connect handling

I started using your great library for a project of mine and I stumbled over this block of code. The changes I made, make it imo more readable and less redundant.

As the commit title states, this is pure refactoring, there shouldn't be any functional changes resulting from this (as I'm only copying references). I still tested it, just in case, and data manipulation was still working fine (as expected).