added instance parameter nextX and nextY