logic problem. A bit tricky.