finish main codes