main functions finished