connect function now takes an optional callback