improved wire snap function