Implemented Piyavsky's method