Phylogeny and the function of REM sleep