Generalize 'type' function and clean up 'connections' code