Adds automatic detection of source connections.
Additions code clean up and tuning.