workable but slow parallel version