optimized the closing of the activities