changed place where we create and close connections