detect cycle