removed commented out code and added cycle detection validation