problem 4 solved but a bit slow