finish main functions