made solution 4 more efficient