optimize reverse list function