Final Code
Partial Automation of fixing the disconncted components
minor fix