keeps track of already visited positions