Updated solution 3