Updated the REM-detection algorithm.