What are the main functions of the reticular formation?