finished ex1 and aftd function