Fixed file traversal to wrap back to beginning