More connection improvements, general code cleanup