reedited version

it gives the same result, but with fewer functions