unified all main functions