Created function get next coord, updated code a bit