Fixed bug in replaceComponent to remove inputs and outputs correctly