More pythonic. Cycle detector. Merge last changes from coolo.