added optional callback to connect