Coordinate string "x,y x,y x,y" was getting converted to "x,yx,y x,y"... by replaceFirst; fixed by adding anchor "^" to regular expression.