Fixes and finished Queyranne's algorithm