Change recursion to cycle in getFreeLocation