The problems must relate to the while(coords.....)-loop..., because coords_x & coords_y immediately get their values.