complete the main functions