finished, but slow and unreliable solution