WIP: refactor detect_sources