added segment placing logic