solution 4 added which was adopted from dan